<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head>
    <meta charset="UTF-8">
    <meta th:name="_csrf" th:content="${_csrf.token}"/>
    <!-- 默认的header name是X-CSRF-TOKEN -->
    <meta th:name="_csrf_header" th:content="${_csrf.headerName}"/>
    <title>我的钱包</title>
    <link rel="stylesheet" th:href="@{/static/component/pear/css/pear.css}" />
    <!-- jquery-->
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <!--bootstrap-->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>

    <!--    引入alibaba iconfont-->
    <link rel="stylesheet" href="//at.alicdn.com/t/font_2608271_v7p87hrx9q.css">
    <link rel="stylesheet" type="text/css" href="http://at.alicdn.com/t/font_2994454_wlpdbkmmipc.css">
    <!--css-->
    <link rel="stylesheet" th:href="@{/static/resource/css/reset.css}"/>
    <link rel="stylesheet" th:href="@{/static/resource/css/index.css}"/>
    <link rel="stylesheet" th:href="@{/static/resource/css/cart.css}"/>
    <link rel="stylesheet" th:href="@{/static/resource/css/home.css}"/>
    <link rel="stylesheet" th:href="@{/static/resource/css/order.css}"/>
    <link rel="stylesheet" th:href="@{/static/resource/css/common/common.css}"/>
    <link rel="stylesheet" th:href="@{/static/js/directives/css/search.css}"/>
    <link rel="stylesheet" th:href="@{/static/js/directives/css/focusImg.css}"/>
    <link rel="stylesheet" th:href="@{/static/js/directives/css/focusImgMult.css}"/>
    <link rel="stylesheet" th:href="@{/static/js/directives/css/ulBox2.css}"/>
    <!--    layui-->
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}">

    <script th:src="@{/static/component/layui/layui.js}"></script>
    <script th:src="@{/static/component/pear/pear.js}"></script>


</head>


<style>


    * {
        box-sizing: border-box;
    }

    /* 下拉框*/

    .dropbtn {
        border: none;
        cursor: pointer;
    }

    .dropdown {
        position: relative;
        display: inline-block;
        z-index: 100;
        margin-left:25px
    }

    .dropdown-content {
        display: none;
        background-color: #f9f9f9;
        min-width: 50px;
        overflow: auto;
        box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
        z-index: 1;
    }

    .dropdown-content a {
        color: black;
        text-decoration: none;
        display: block;
    }

    .dropdown a:hover {background-color: #f1f1f1}

    .show {display:block;}

/*    内容*/
    #box{

        width: 100%;
        height: 830px;

    }

    #leftbox{

        width: 200px;
        height: 400px;
        border: 2px solid #666666;


        float: left;
        margin-left: 160px;
        margin-top: 70px;
    }

    #leftMenu{

        width: 150px;
        height: 200px;
        /*border: 1px solid;*/
        margin: 0 auto;
        margin-top: 23%
    }


    #leftMenu ul>li
    {
        list-style: none;
        line-height: 35px;
        margin-left: 40px;
    }
    #leftMenu ul>li>a{

        text-decoration: none;
        color: #000000;

    }



    #rightBox{

        width: 60%;
        height: 700px;
        border: 1px solid  #666666;

        float: left;
        margin-left: 20px;
        margin-top: 40px;
    }

    #rightContent{

        /*width: 70%;*/
        /*height: 520px;*/
        /*margin: 0 auto;*/
    }



    .info{

        line-height: 40px;
        /*两行超出变成...*/
        word-break: break-all;
        text-overflow: ellipsis;
        overflow: hidden;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
    }

    .topbar a:hover{
        color: orange;
    }


</style>




<body>

<!--头部工具栏-->
<div class="topbar">
    <div class="container">
        <div class="topbar_nav fl">
            <ul>
                <li><a th:href="@{/web/index/}">首页</a></li>
                <li><a th:href="@{/web/couponsActivity/toCouponsActivity}">领劵中心</a></li>
                <li><a th:href="@{/web/seckill/toSearchSeckillPage}">秒杀</a></li>
                <li><a href="https://github.com/youzhengjie9/cloud-mall">项目链接</a></li>
            </ul>
        </div>
        <div class="topbar_cart fr">
            <a href="/web/cart/tocart">购物车</a>
        </div>

        <div class="topbar_cart fr">
            <a href="/web/order/toOrderPage">我的订单</a>
        </div>
        <div class="topbar_cart fr">
            <a href="/web/seckill/toSeckillSuccessList">秒杀成功订单</a>
        </div>
        <div class="topbar_info fr" style="width:220px">
            <form name="logoutform" th:action="@{/web/logout/logout}" method="post"></form>
            <a class="nav-link" th:href="@{/web/register/toregister}">注册</a>
            <a class="nav-link" sec:authorize="isAnonymous()" th:href="@{/web/login/toLoginPage}">登录</a>
            <a sec:authorize="isAuthenticated()" class="nav-link dropbtn" onclick="myFunction()">[[${username}]]</a>
            <a href="#" onclick="kefu(1)">人工客服</a>
            <div class="dropdown">
                <div id="myDropdown" class="dropdown-content" style="width: 120px;height: 70px">
                    <a th:href="@{/web/center/toBaseInfo}" style="width: 100px;height: 30px;">个人中心</a>
                    <a href="javascript:document.logoutform.submit();" style="width: 100px;height: 30px;">退出登录</a>
                </div>
            </div>
        </div>
    </div>
</div>


<!-- 充值模态框-->
<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
    <div class="modal-dialog">
        <form id="rechargeForm" method="post" action="#" autocomplete="off">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel1">充值</h4>
            </div>
            <div class="modal-body">
                卡号：<input type="text" class="form-control" name="cardNumber" required>
                密码：<input type="text" class="form-control" name="password" required>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="recharge()">充值</button>
            </div>
        </div>
        </form>

    </div>
</div>


<!--  获取充值卡-->
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2" aria-hidden="true">
    <div class="modal-dialog">
        <form method="post" action="#" autocomplete="off">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel2">获取充值卡</h4>
                </div>
                <div class="modal-body">
                    <img style="width: 50%;height: 230px;margin-left: 22%" th:src="@{/static/img/chongzhi/cz.jpg}">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </form>

    </div>
</div>


<!--左侧导航以及右侧内容-->
<div id="box">

    <div id="leftbox">

        <div id="leftMenu">

            <span class="iconfont icon-zhanghu" style="color: red;font-size: 25px;"></span>
            <span><b>我的账户</b></span>
            <ul>
                <li>
                    <a th:href="@{/web/center/toBaseInfo}">个人信息</a>
                </li>
                <li>
                    <a th:href="@{/web/center/toChangePassword}">修改密码</a>
                </li>

                <li>
                    <a href="#" style="color: red;pointer-events: none;">我的钱包</a>
                </li>

                <li>
                    <a th:href="@{/web/center/toCouponsRecord}">我的优惠券</a>
                </li>


            </ul>

        </div>



    </div>


    <!--  右边-->

    <div id="rightBox">


        <!-- 信息内容-->
        <div id="rightContent">

            <div style="width: 98%;height: 121px" class="pear-container">

                <div class="layui-col-md6">
                    <div class="layui-card">
                        <div class="layui-card-body layui-row layui-col-space7" style="margin-top: 30px">

                            <span>账户余额：</span>
                            <span style="color: orange"><b>[[${userMoney}]]元</b></span>

                            <input style="width: 50px;color: black;margin-left: 20px;" class="btn btn-primary btn-sm" type="button" value="充值" data-toggle="modal" data-target="#myModal1">

                            <input style="width: 50px;color: black;margin-left: 10px;" class="btn btn-default btn-sm" type="button" value="提现" onclick="tixian()">

                            <input style="width: 85px;color: black;margin-left: 10px;" class="btn btn-success btn-sm" type="button" value="获取充值卡" data-toggle="modal" data-target="#myModal2">


                        </div>
                    </div>


                </div>

            </div>



            <div style="width: 98%;height: 421px">
                <span><b>用户近10次充值记录:</b></span><br/>
                <table class="table table-hover">
                    <tr>
                        <td>卡号</td>
                        <td>面值</td>
                        <td>充值时间</td>
                    </tr>
                    <tr th:if="${rechargeRecords.size()>0}" th:each="record:${rechargeRecords}">

                        <td th:text="${record.getCardNumber()}"></td>
                        <td th:text="${record.getMoney()}"></td>
                        <td th:text="${record.getCreated()}"></td>
                    </tr>
                </table>

            </div>

        </div>




    </div>

</div>


</body>

<script>
    // 获取<meta>标签中封装的_csrf信息 ,否则会请求403
    var token = $("meta[name='_csrf']").attr("content");
    var header = $("meta[name='_csrf_header']").attr("content");
    var headers = {"X-CSRF-TOKEN": token}
    /* 点击按钮，下拉菜单在 显示/隐藏 之间切换 */
    function myFunction() {
        document.getElementById("myDropdown").classList.toggle("show");
    }

    // 点击下拉菜单意外区域隐藏
    window.onclick = function(event) {
        if (!event.target.matches('.dropbtn')) {

            var dropdowns = document.getElementsByClassName("dropdown-content");
            var i;
            for (i = 0; i < dropdowns.length; i++) {
                var openDropdown = dropdowns[i];
                if (openDropdown.classList.contains('show')) {
                    openDropdown.classList.remove('show');
                }
            }
        }
    }


    function recharge()
    {

        let b = confirm('确定要进行充值？');

        if(b==true)
        {
            $.ajax({
                url:'/web/center/recharge',
                data: $('#rechargeForm').serialize(),
                dataType:'json',
                type:'post',
                headers: headers,
                success:function(result){
                    if(result.success){
                         alert(result.msg);
                         window.location.reload();
                    }else{
                        alert(result.msg);
                        window.location.reload();
                    }
                }
            })

        }


    }


    function tixian() {
        alert('暂时不能提现');
    }

    function kefu(e) {
        $.ajax({
            url:'/web/chat/HasGotoKefu',
            dataType:'json',
            type:'get',
            success:function(result){

                if(result==true){
                    window.location.href='http://localhost:5677/chat/toChat';
                }else {
                    alert('当前咨询人数过多,客服都忙不过来了,请等会儿再咨询！')
                }

            },
            error:function () {
                alert('您可能还没有登录,请登录!')
            }
        })

    }
</script>




</html>